import 'dart:convert';

import 'package:badges/badges.dart';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'package:sp_util/sp_util.dart';
import 'package:yp/config/config.dart';
import 'package:yp/helper.dart';
import 'package:yp/pages/invite_koc/view.dart';
import 'package:yp/utils/util.dart';

import '../../../router.dart';
import 'logic.dart';
import 'state.dart';

class MyPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _MyPage();
  }
}

class _MyPage extends State<MyPage> {
  final MyLogic logic = Get.put(MyLogic());
  final MyState state = Get.find<MyLogic>().state;

  static const platform = const MethodChannel("com.elitesland/pay");

  @override
  void deactivate() {
    // TODO: implement deactivate
    super.deactivate();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Color(0xfff5f5f5),
      body: GetBuilder<MyLogic>(
        builder: (logic) {
          return Container(
            child: SmartRefresher(
              controller: state.controller1,
              header: CustomHeader(
                builder: (BuildContext context, RefreshStatus mode) {
                  Widget body;
                  if (mode == RefreshStatus.completed) {
                    body = CupertinoActivityIndicator();
                  }
                  return Container(
                    height: 55.0,
                    child: Center(child: body),
                  );
                },
              ),
              enablePullDown: true,
              onRefresh: logic.refreshData,
              child: ListView(
                children: [
                  _personalInformationWidget(),
                  _myOrderWidget(),
                  // SizedBox(height: 15),
                  _doTaskRewardWidget(), //任务列表
                  _getImagesWidget(), // 中间轮播图
                  // SizedBox(height: 10),
                  _itemListWidget(),
                  _goodsListWidget(),
                  Container(
                    height: setWidth(30),
                    color: Colors.transparent,
                  ),
                ],
              ),
            ),
          );
        },
      ),
    );
  }

  // 个人信息
  Widget _personalInformationWidget() {
    var infoConfig = MyInfoConfig(state.diyConfigData);

    String phoneStr = state.userInformationData == null
        ? ''
        : state.userInformationData['mobile'];
    if (phoneStr.length == 11) {
      phoneStr = '${phoneStr.substring(0, 4)}**${phoneStr.substring(8, 11)}';
    }
    var backgroundColors = infoConfig.backgroundColor.split(',');
    if (backgroundColors == null || backgroundColors.isEmpty) {
      backgroundColors = ['#ea5504', '#ea5504'];
    } else if (backgroundColors.length < 2) {
      backgroundColors.add(backgroundColors.first);
    }
    String logoImage = '';
    if (state.userInformationData != null) {
      logoImage = state.userInformationData['logo'] ?? '';
    } else {
      if (infoConfig.defaultAvater.isEmpty == false) {
        logoImage = infoConfig.defaultAvater;
      }
    }

    return Container(
      padding: EdgeInsets.only(top: context.mediaQueryPadding.top),
      decoration: BoxDecoration(
          gradient: LinearGradient(
              begin: Alignment.topCenter,
              end: Alignment.bottomCenter,
              colors:
                  backgroundColors.map((e) => HexColor.fromHex(e)).toList())),
      child: Column(
        children: [
          GestureDetector(
            onTap: () {
              print('设置');
              Get.toNamed(RouteConfig.setUp);
              // // return;
              // Get.toNamed(
              //   RouteConfig.randomAmount,
              //   arguments: {
              //     "activity": {
              //       "activity_num_id": 2112270010001,
              //       "event_num_id": 2112270010007,
              //     }
              //   },
              // );
            },
            behavior: HitTestBehavior.opaque,
            child: Container(
              padding: EdgeInsets.symmetric(horizontal: setWidth(30)),
              alignment: Alignment.centerRight,
              child: Image.asset(
                'assets/images/setUp_image.png',
                width: setWidth(60),
                height: setWidth(60),
                color: infoConfig.toolTextColor,
                fit: BoxFit.fill,
              ),
            ),
          ),
          Padding(
            padding: EdgeInsets.only(
              left: setWidth(34),
              top: setWidth(12),
              right: setWidth(34),
              bottom: setWidth(42),
            ),
            child: Row(
              children: [
                // 头像
                InkWell(
                  onTap: () {
                    print('会员信息 点击事件！！！ ');
                    Get.toNamed(RouteConfig.memberInformation,
                            arguments: state.userInformationData)
                        .then((value) {
                      logic.onInit();
                    });
                  },
                  child: ClipOval(
                    child: logoImage.isNotEmpty
                        ? CachedNetworkImage(
                            imageUrl: logoImage,
                            width: setWidth(100),
                            height: setWidth(100),
                            errorWidget: (context, url, error) => Container(
                              child: Image.asset(
                                'assets/images/defaultAvatar_image.png',
                                width: setWidth(100),
                                height: setWidth(100),
                                fit: BoxFit.cover,
                              ),
                            ),
                            fit: BoxFit.cover,
                          )
                        : Image.asset(
                            'assets/images/defaultAvatar_image.png',
                            width: setWidth(100),
                            height: setWidth(100),
                            fit: BoxFit.cover,
                          ),
                  ),
                ),
                SizedBox(
                  width: setWidth(12),
                ),
                state.userInformationData == null
                    ? Text(
                        '未登录',
                        style: TextStyle(
                          color: infoConfig.toolTextColor,
                          fontSize: 17,
                        ),
                      )
                    : Expanded(
                        child: Container(
                          height: setWidth(130),
                          child: Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [
                              Row(
                                children: [
                                  // 手机号
                                  Text(
                                    phoneStr,
                                    style: TextStyle(
                                      color: infoConfig.toolTextColor,
                                      fontSize: 16,
                                    ),
                                  ),
                                  SizedBox(
                                    width: setWidth(10),
                                  ),
                                  // 会员类型
                                  Container(
                                    width: setWidth(90),
                                    height: setWidth(28),
                                    alignment: Alignment.center,
                                    decoration: BoxDecoration(
                                      border: Border.all(
                                        color: Color(0x80FFFFFF),
                                        width: setWidth(1),
                                      ),
                                      borderRadius:
                                          BorderRadius.circular(setWidth(14)),
                                    ),
                                    child: Text(
                                      state.userInformationData[
                                              'vip_type_name'] ??
                                          '',
                                      style: TextStyle(
                                        color: infoConfig.toolTextColor,
                                        fontSize: 9,
                                      ),
                                    ),
                                  ),
                                ],
                              ),
                              // 资料完善程度
                              state.userInformationData['info_progress'] !=
                                          '' &&
                                      state.userInformationData[
                                              'info_progress'] !=
                                          null
                                  ? (double.parse(state.userInformationData[
                                                  'info_progress']
                                              .toString()) >=
                                          100
                                      ? Container()
                                      : Column(
                                          crossAxisAlignment:
                                              CrossAxisAlignment.start,
                                          children: [
                                            Text(
                                              '信息完善度：${state.userInformationData['info_progress']}/100 >',
                                              style: TextStyle(
                                                color: infoConfig.toolTextColor,
                                                fontSize: 10,
                                              ),
                                            ),
                                            Stack(
                                              children: [
                                                Container(
                                                  width: setWidth(140),
                                                  height: setWidth(10),
                                                  decoration: BoxDecoration(
                                                    color: infoConfig.toolColor,
                                                    borderRadius:
                                                        BorderRadius.circular(
                                                            setWidth(5)),
                                                  ),
                                                ),
                                                Container(
                                                  width: double.parse(state
                                                          .userInformationData[
                                                              'info_progress']
                                                          .toString()) /
                                                      100 *
                                                      setWidth(140),
                                                  height: setWidth(10),
                                                  decoration: BoxDecoration(
                                                    color: infoConfig
                                                        .toolTextColor,
                                                    borderRadius:
                                                        BorderRadius.circular(
                                                            setWidth(5)),
                                                  ),
                                                ),
                                              ],
                                            ),
                                          ],
                                        ))
                                  : Text(
                                      '完善会员信息可获得80积分,点击完善～',
                                      style: TextStyle(
                                        color: infoConfig.toolTextColor,
                                        fontSize: 10,
                                      ),
                                    ),
                              InkWell(
                                onTap: () {
                                  print('绑定天然气 ！！！！');
                                  Get.toNamed(RouteConfig.myGas, parameters: {
                                    'gasStr':
                                        state.userInformationData['gas_code'],
                                  }).then((value) {
                                    print(
                                        '++++++++++++++++++ 绑定天然气返回 ==================');
                                    logic.onInit();
                                  });
                                  // 用户信息里面的天气账号信息字段  gas_code
                                },
                                child: Text(
                                  '+点击绑定燃气用户',
                                  style: TextStyle(
                                    color: infoConfig.toolTextColor,
                                    fontSize: 10,
                                  ),
                                ),
                              ),
                              // GestureDetector(
                              //     onTap: (){
                              //       Get.toNamed(RouteConfig.seckillHome);
                              //     },
                              //     child: Text('测试秒杀'))
                            ],
                          ),
                        ),
                      ),
              ],
            ),
          ),
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceEvenly,
            children: infoConfig.walletSigns.map((e) {
              String name = '';
              String val = '';
              if (e == '1') {
                name = '优惠券';
                val = state.availableCouponsNum.toString();
              } else if (e == '2') {
                name = '积分';
                val = state.userIntegralNum.toString();
              } else if (e == '3') {
                name = '钱包';
                val = state.walletNum.toString();
                if (Config.loginScreenStyle == '1') {
                  return SizedBox();
                }
              }
              return InkWell(
                onTap: () {
                  if (e == '1') {
                    print('优惠券 优惠券  点击事件！！！c');
                    Get.toNamed(RouteConfig.myCoupon, arguments: {'status': 1})
                        .then((value) {
                      logic.onInit();
                    });
                  } else if (e == '2') {
                    Get.toNamed(RouteConfig.myPoints);
                  } else if (e == '3') {
                    Get.toNamed(RouteConfig.myWallet).then((value) {
                      logic.onInit();
                      logic.update();
                    });
                  }
                },
                child: Container(
                  width: setWidth(250),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: [
                      Text(
                        val,
                        style: TextStyle(
                          color: infoConfig.toolTextColor,
                          fontSize: 16,
                        ),
                      ),
                      SizedBox(
                        height: setWidth(12),
                      ),
                      Text(
                        name,
                        style: TextStyle(
                          color: infoConfig.toolTextColor,
                          fontSize: 12,
                        ),
                      ),
                    ],
                  ),
                ),
              );
            }).toList(),
          ),
          Padding(
            padding: EdgeInsets.only(
              left: setWidth(60),
              top: setWidth(30),
              right: setWidth(60),
            ),
            child: _memContainer(
              infoConfig.mem_card_image,
              padding: EdgeInsets.only(
                left: setWidth(20),
                top: setWidth(10),
                right: setWidth(20),
              ),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                crossAxisAlignment: CrossAxisAlignment.center,
                children: [
                  Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      // infoConfig.mem_icon == null
                      //     ? SizedBox(
                      //         height: setWidth(14),
                      //       )
                      //     : Image.network(
                      //         infoConfig.mem_icon,
                      //         width: setWidth(50),
                      //         height: setWidth(36),
                      //         fit: BoxFit.fill,
                      //       ),
                      CachedNetworkImage(
                        width: setWidth(50),
                        height: setWidth(36),
                        imageUrl: infoConfig.mem_icon,
                        errorWidget: (context, url, error) {
                          return SizedBox(
                            width: setWidth(50),
                            height: setWidth(36),
                            child: Image.asset(
                              'assets/images/collectCouponsCenter_image.png',
                              fit: BoxFit.cover,
                            ),
                          );
                        },
                      ),
                      Text(
                        '会员商城',
                        style: TextStyle(
                          color: infoConfig.mem_title_color,
                          fontSize: 12,
                        ),
                      ),
                    ],
                  ),
                  InkWell(
                    onTap: () {
                      print('================== 查看会员 点击事件 ==================');
                      Get.toNamed(RouteConfig.membershipCardHomePage);
                    },
                    child: Column(
                      children: [
                        SizedBox(
                          height: setWidth(14),
                        ),
                        Container(
                          padding:
                              EdgeInsets.symmetric(horizontal: setWidth(14)),
                          height: setWidth(44),
                          alignment: Alignment.center,
                          decoration: BoxDecoration(
                            gradient: LinearGradient(
                              begin: Alignment.centerLeft,
                              end: Alignment.centerRight,
                              colors: infoConfig.mem_button_value.length > 1
                                  ? infoConfig.mem_button_value
                                  : [Color(0xff7E4303), Color(0xff582E02)],
                            ),
                            borderRadius: BorderRadius.circular(setWidth(22)),
                          ),
                          child: Text(
                            '查看会员',
                            style: TextStyle(
                              color: infoConfig.mem_button_text_color,
                              fontSize: 10,
                            ),
                          ),
                        ),
                      ],
                    ),
                  ),
                ],
              ),
            ),
          ),
        ],
      ),
    );
  }

  Widget _memContainer(String card, {EdgeInsets padding, Widget child}) {
    if (card == null || card == '') {
      return Container(
          height: setWidth(90),
          decoration: BoxDecoration(
            borderRadius: BorderRadius.circular(setWidth(20)),
            image: DecorationImage(
              image: AssetImage('assets/images/workbenchBj.png'),
              fit: BoxFit.cover,
            ),
          ),
          padding: padding,
          child: child);
    }
    return Container(
        height: setWidth(90),
        decoration: BoxDecoration(
          borderRadius:
              BorderRadius.vertical(top: Radius.circular(setWidth(20))),
          image: DecorationImage(
            image: NetworkImage(card),
            fit: BoxFit.cover,
          ),
        ),
        padding: padding,
        child: child);
  }

  // 我的订单
  Widget _myOrderWidget() {
    int index = 0; // 1.评价有礼   2. 待评价数量   0.不显示
    if (state.unCommentCount != '0') {
      if (state.pingJiaList.length > 0) {
        if (state.pingJiaList[0]['award_count'] > 0) {
          index = 1;
        }
      }
    }
    return Container(
      height: setWidth(276),
      color: Colors.white,
      child: Column(
        children: [
          Container(
            height: setWidth(88),
            padding: EdgeInsets.only(
              left: setWidth(28),
              right: setWidth(22),
            ),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Text(
                  '我的订单',
                  style: TextStyle(
                    color: Color(0xff333333),
                    fontSize: 16,
                  ),
                ),
                InkWell(
                  onTap: () {
                    print('=========== 查看全部订单 点击事件！！！');
                    // Get.toNamed(RouteConfig.allOrders);
                    Get.toNamed(RouteConfig.order, arguments: {'index': 0});
                  },
                  child: Container(
                    height: setWidth(88),
                    child: Row(
                      children: [
                        Text(
                          '查看全部订单',
                          style: TextStyle(
                            color: Color(0xffB7B7B7),
                            fontSize: 12,
                          ),
                        ),
                        SizedBox(
                          width: setWidth(8),
                        ),
                        Image.asset(
                          'assets/images/icon-left.png',
                          width: setWidth(10),
                          height: setWidth(18),
                          fit: BoxFit.cover,
                          color: Color(0xffadadad),
                        ),
                      ],
                    ),
                  ),
                ),
              ],
            ),
          ),
          Divider(
            height: setWidth(2),
            indent: setWidth(24),
            endIndent: 0,
            color: Color(0xffefefef),
          ),
          Row(
            children: [
              InkWell(
                onTap: () {
                  print('我的点单  代付款  点击事件');
                  Get.toNamed(RouteConfig.order, arguments: {'index': 1});
                },
                child: Container(
                  width: setWidth(150),
                  height: setWidth(186),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.center,
                    mainAxisAlignment: MainAxisAlignment.center,
                    // 角标 未付款
                    children: [
                      Badge(
                          badgeContent: Text(state.unPayCount,
                              style: TextStyle(color: Colors.white)),
                          showBadge: state.unPayCount == '0' ? false : true,
                          child: Image.asset(
                            'assets/images/order1.png',
                            width: setWidth(60),
                            height: setWidth(60),
                            fit: BoxFit.cover,
                          )),
                      SizedBox(
                        height: setWidth(20),
                      ),
                      Text(
                        '待付款',
                        style: TextStyle(
                          color: Color(0xff666666),
                          fontSize: 13,
                        ),
                      ),
                    ],
                  ),
                ),
              ),
              InkWell(
                onTap: () {
                  print('我的点单  待配送/自提  点击事件');
                  Get.toNamed(RouteConfig.order, arguments: {'index': 2});
                },
                child: Container(
                  width: setWidth(150),
                  height: setWidth(186),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.center,
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      // 角标 待配送/自提
                      Badge(
                          badgeContent: Text(state.arrivedCount,
                              style: TextStyle(color: Colors.white)),
                          showBadge: state.arrivedCount == '0' ? false : true,
                          child: Image.asset(
                            'assets/images/order2.png',
                            width: setWidth(60),
                            height: setWidth(60),
                            fit: BoxFit.cover,
                          )),
                      SizedBox(
                        height: setWidth(20),
                      ),
                      Text(
                        '待配送/自提',
                        style: TextStyle(
                          color: Color(0xff666666),
                          fontSize: 13,
                        ),
                      ),
                    ],
                  ),
                ),
              ),
              InkWell(
                onTap: () {
                  print('我的点单  已发货  点击事件');
                  Get.toNamed(RouteConfig.order, arguments: {'index': 3});
                },
                child: Container(
                  width: setWidth(150),
                  height: setWidth(186),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.center,
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      // 角标 待发货
                      Badge(
                          badgeContent: Text(state.notSendCount,
                              style: TextStyle(color: Colors.white)),
                          showBadge: state.notSendCount == '0' ? false : true,
                          child: Image.asset(
                            'assets/images/order3.png',
                            width: setWidth(60),
                            height: setWidth(60),
                            fit: BoxFit.cover,
                          )),
                      SizedBox(
                        height: setWidth(20),
                      ),
                      Text(
                        '已发货',
                        style: TextStyle(
                          color: Color(0xff666666),
                          fontSize: 13,
                        ),
                      ),
                    ],
                  ),
                ),
              ),
              InkWell(
                onTap: () {
                  print('我的点单  待评价  点击事件');
                  Get.toNamed(RouteConfig.order, arguments: {'index': 4});
                },
                child: Container(
                  width: setWidth(150),
                  height: setWidth(186),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.center,
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      if (index == 1)
                        Stack(
                          alignment: Alignment.topCenter,
                          children: [
                            Padding(
                              padding: EdgeInsets.only(top: setWidth(20)),
                              child: Image.asset(
                                'assets/images/order4.png',
                                width: setWidth(60),
                                height: setWidth(60),
                                fit: BoxFit.cover,
                              ),
                            ),
                            Row(
                              mainAxisAlignment: MainAxisAlignment.end,
                              children: [
                                Container(
                                  alignment: Alignment.center,
                                  decoration: BoxDecoration(
                                    color: Color(0xfff99411),
                                    borderRadius:
                                        BorderRadius.circular(setWidth(5)),
                                  ),
                                  padding: EdgeInsets.symmetric(
                                      horizontal: setWidth(5),
                                      vertical: setWidth(1)),
                                  child: Text(
                                    '评价有礼',
                                    style: TextStyle(
                                      color: Colors.white,
                                      fontSize: 7,
                                    ),
                                  ),
                                ),
                              ],
                            ),
                          ],
                        ),
                      if (index != 1)
                        Badge(
                          badgeContent: Text(
                            state.unCommentCount,
                            style: TextStyle(
                              color: Colors.white,
                            ),
                          ),
                          showBadge: state.unCommentCount == '0' ? false : true,
                          child: Image.asset(
                            'assets/images/order4.png',
                            width: setWidth(60),
                            height: setWidth(60),
                            fit: BoxFit.cover,
                          ),
                        ),
                      SizedBox(
                        height: setWidth(20),
                      ),
                      Text(
                        '待评价',
                        style: TextStyle(
                          color: Color(0xff666666),
                          fontSize: 13,
                        ),
                      ),
                      if (index == 1)
                        SizedBox(
                          height: setWidth(20),
                        ),
                    ],
                  ),
                ),
              ),
              InkWell(
                onTap: () {
                  print('我的点单  售后/退货  点击事件');
                  Get.toNamed(RouteConfig.order, arguments: {'index': 5});
                },
                child: Container(
                  width: setWidth(150),
                  height: setWidth(186),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.center,
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      // 角标 售后/退货
                      Badge(
                          badgeContent: Text(state.serviceCount,
                              style: TextStyle(color: Colors.white)),
                          showBadge: state.serviceCount == '0' ? false : true,
                          child: Image.asset(
                            'assets/images/order4.png',
                            width: setWidth(60),
                            height: setWidth(60),
                            fit: BoxFit.cover,
                          )),

                      SizedBox(
                        height: setWidth(20),
                      ),
                      Text(
                        '售后/退货',
                        style: TextStyle(
                          color: Color(0xff666666),
                          fontSize: 13,
                        ),
                      ),
                    ],
                  ),
                ),
              ),
            ],
          ),
        ],
      ),
    );
  }

  // 做任务，得奖励 列表
  Widget _doTaskRewardWidget() {
    return state.taskData.isEmpty
        ? SizedBox()
        : Container(
            color: Colors.white,
            margin: EdgeInsets.only(top: setWidth(20)),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Container(
                  height: setWidth(86),
                  padding: EdgeInsets.symmetric(horizontal: setWidth(24)),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Text(
                        '做任务，得奖励',
                        style: TextStyle(
                          color: Color(0xff333333),
                          fontSize: 16,
                          fontWeight: FontWeight.bold,
                        ),
                      ),
                      InkWell(
                        onTap: () {
                          print('去领奖 点击事件！！！');
                          Get.toNamed(RouteConfig.vipTask);
                        },
                        child: Container(
                          height: setWidth(86),
                          child: Row(
                            children: [
                              Text(
                                '去领奖',
                                style: TextStyle(
                                  color: Color(0xffB7B7B7),
                                  fontSize: 12,
                                ),
                              ),
                              SizedBox(
                                width: setWidth(8),
                              ),
                              Image.asset(
                                'assets/images/icon-left.png',
                                width: setWidth(10),
                                height: setWidth(18),
                                fit: BoxFit.cover,
                                color: Color(0xffadadad),
                              ),
                            ],
                          ),
                        ),
                      ),
                    ],
                  ),
                ),
                Divider(
                  height: setWidth(2),
                  indent: setWidth(20),
                  endIndent: 0,
                  color: Color(0xffefefef),
                ),
                Column(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: state.taskData
                      .asMap()
                      .map((key, value) {
                        return MapEntry(
                          key,
                          _taskItemWidget(
                            index: key,
                            mod: value,
                          ),
                        );
                      })
                      .values
                      .toList(),
                ),
              ],
            ),
          );
  }

  // 任务 item
  Widget _taskItemWidget({
    int index,
    MyTaskModel mod,
  }) {
    if (Config.loginScreenStyle == '1' && mod.name == "邀请好友,得奖励") {
      return Container();
    }
    return InkWell(
        onTap: () {
          print('******** 去完善 ******** 点击事件 ********');
          if (mod.id == 1) {
            //完善用户信息
            Get.toNamed(RouteConfig.memberInformation);
          } else if (mod.id == 2) {
            //签到
            Get.toNamed(RouteConfig.signIn).then((value) {
              // logic.onInit();
              logic.signInRefresh(); // 签到成功 刷新
            });
          } else if (mod.id == 3) {
            //邀请
            Get.toNamed(RouteConfig.inviteFriend);
          }
        },
        child: Container(
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Container(
                height: setWidth(136),
                padding: EdgeInsets.symmetric(horizontal: setWidth(20)),
                child: Row(
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: [
                    Image.asset(
                      'assets/images/${mod.icon}.png',
                      width: setWidth(80),
                      height: setWidth(80),
                      fit: BoxFit.cover,
                    ),
                    Expanded(
                      child: Padding(
                        padding: EdgeInsets.symmetric(horizontal: setWidth(24)),
                        child: Text(
                          mod.name,
                          style: TextStyle(
                            color: Color(0xff666666),
                            fontSize: 14,
                          ),
                        ),
                      ),
                    ),
                    Container(
                      decoration: BoxDecoration(
                        borderRadius: BorderRadius.circular(setWidth(25)),
                        border: Border.all(
                          color: Color(0xffea5504),
                          width: setWidth(1),
                        ),
                      ),
                      height: setWidth(50),
                      width: setWidth(130),
                      alignment: Alignment.center,
                      child: Text(
                        mod.actionText,
                        style: TextStyle(
                          color: Color(0xffea5504),
                          fontSize: 13,
                        ),
                      ),
                    ),
                  ],
                ),
              ),
              Divider(
                height: setWidth(1),
                color: Color(0xffefefef),
                indent: setWidth(20),
                endIndent: 0,
              ),
            ],
          ),
        ));
  }

  Widget _getImagesWidget() {
    if (Config.loginScreenStyle == '1') {
      return Row();
    }
    List items = state.diyConfigData == null
        ? []
        : state.diyConfigData['personal_config_mem_center']['top_banner_list'];
    return Container(
      padding: EdgeInsets.only(
          top: setWidth(20), left: setWidth(20), right: setWidth(20)),
      child: Column(
        children: items.map((e) => _imageWidget(e)).toList(),
      ),
    );
  }

  // 图片
  Widget _imageWidget(dynamic e) {
    return InkWell(
      onTap: () {
        // logic.applyToMarketing();
        Get.toNamed(RouteConfig.inviteKocPage);
        // Get.to(() => InviteKocPage());
      },
      child: Container(
        padding: EdgeInsets.only(bottom: setWidth(20)),
        child: ClipRRect(
          borderRadius: BorderRadius.circular(setWidth(10)),
          child: Image.network(
            e['top_banner_image'],
            width: setWidth(712),
            height: setWidth(200),
            fit: BoxFit.cover,
          ),
        ),
      ),
    );
  }

  // item List
  Widget _itemListWidget() {
    // List itemList = [
    //   '优惠券', '我的收藏', '地址管理', '签到送积分',
    //   '账户安全', '联系我们', '超级团', '会员中心',
    //   '邀请好友有礼', '关于我们', '领券中心', '设置',
    //   '帮助中心', '意见反馈', '服务协议', '网格员中心',
    //   '预售订单', '拼团订单', '我的燃气', 'KOC中心',
    // ];
    // List itemList = [
    //   '优惠券', '地址管理', '领券中心', 'KOC中心', '预售订单'
    //   // '发票', '发票详情', '我的流量', 'KOC中心4',
    // ];
    List itemList = state.diyConfigData == null
        ? []
        : state.diyConfigData['personal_config_mem_center']
            ['quick_navigation_config']['quick_navigation_list'];
    // List imageList = [
    //   'myCoupon_image.png', 'homePositioning_image.png',
    //   'collectCouponsCenter_image.png', 'KOC.png',
    //   // 'myCoupon_image.png', 'homePositioning_image.png', 'collectCouponsCenter_image.png', 'KOC.png',
    // ];

    // List itemList = [];
    // if (list.length > 0) {
    //   list.forEach((element) {
    //     if (element['name'] != '邀请好友有礼') {
    //       itemList.add(element);
    //     }
    //   });
    // }
    List itemList2 = itemList.where((element) {
      print('itemlist:');
      print(element['id']);
      print(element['name']);
      if (Config.loginScreenStyle == '0') {
        return true;
      }
      return !((Config.loginScreenStyle == '1') &&
          (element['name'] == '邀请好友有礼'));
    }).toList();
    return itemList.isEmpty
        ? SizedBox()
        : Container(
            color: Colors.white,
            padding: EdgeInsets.only(
              bottom: setWidth(20),
            ),
            child: Wrap(
              children: itemList2
                  .asMap()
                  .map((key, value) {
                    return MapEntry(
                      key,
                      _itemWidget(
                        index: key,
                        id: value['id'],
                        titleStr: value['name'],
                        imageStr: value['image'],
                      ),
                    );
                  })
                  .values
                  .toList(),
            ),
            // child: Wrap(
            //   spacing: setWidth(2),
            //   children: itemList.asMap().map((key, value) {
            //     return MapEntry(key, _itemWidget(index: key, titleStr: value, imageStr: imageList[key]));
            //   }).values.toList(),
            // ),
          );
  }

  // item
  Widget _itemWidget({
    int index,
    int id,
    String titleStr,
    String imageStr,
  }) {
    return InkWell(
      onTap: () async {
        print(
            'itemList itemList itemList itemList id = $id   index = $index  titleStr = $titleStr ');
        if (id == 12) {
          //设置
          Get.toNamed(RouteConfig.setUp);
        } else if (id == 1) {
          //优惠券
          var _ = await Get.toNamed(RouteConfig.myCoupon);
          logic.couponsInfo();
        } else if (id == 6) {
          // 意见反馈
          Get.toNamed(RouteConfig.opinionFeedback);
        } else if (id == 2) {
          //我的收藏
          Get.toNamed(RouteConfig.myCollectPage); // 登录页面
        } else if (id == 29) {
          //我的燃气
          print(
              '   state.userInformationData = ${state.userInformationData['gas_code']}');
          Get.toNamed(RouteConfig.myGas, parameters: {
            'gasStr': state.userInformationData['gas_code'],
          }).then((value) {
            logic.onInit();
          });
        } else if (id == 3) {
          //地址管理
          Map<String, String> personalCenterMap = {
            'isPersonalCenter': 'true',
          };
          Get.toNamed(
            RouteConfig.addressList,
            parameters: personalCenterMap,
          );
        } else if (id == 11) {
          //领券中心
          var _ = await Get.toNamed(RouteConfig.collectCouponsCentre);
          logic.couponsInfo();
        } else if (id == 30) {
          //会员中心
          // Get.toNamed(RouteConfig.vipTask);
          Get.toNamed(RouteConfig.integralMall);
        } else if (id == 16) {
          //邀请好友有礼
          Get.toNamed(RouteConfig.inviteFriend);
        } else if (id == 28) {
          //我的订阅
          Get.toNamed(RouteConfig.mySubscriptionPage);
        } else if (id == 4) {
          //签到送积分
          Get.toNamed(RouteConfig.signIn).then((value) {
            logic.signInRefresh(); // 签到成功 刷新
          });
        } else if (id == 24) {
          // 预售订单
          Get.toNamed(RouteConfig.preSaleOrder);
        } else if (id == 25) {
          //拼团订单
          Get.toNamed(RouteConfig.tuanOrder);
        } else if (id == 10) {
          //关于我们
          Get.toNamed(RouteConfig.about);
        } else if (id == 22) {
          //帮助中心
          Get.toNamed(RouteConfig.helpPage);
        } else if (id == 7) {
          //TODO：客服电话

        } else if (id == 23) {
          //服务协议
          Get.toNamed(RouteConfig.webview, arguments: {
            "url": "https://img.zrhsh.com/zrhshgg/treaty/fwxy.html",
          });
        } else if (id == 9) {
          //账号安全
          Get.toNamed(RouteConfig.accountSafe);
        } else if (id == 19) {
          //TODO：直播
          // Get.toNamed(RouteConfig.tuanOrder);
        } else if (id == 20) {
          //TODO：付费会员
          // Get.toNamed(RouteConfig.tuanOrder);
        } else if (id == 21) {
          //会员任务
          Get.toNamed(RouteConfig.vipTask);
        } else if (id == 26) {
          Get.toNamed(RouteConfig.collage);
          //TODO: 超级团
          // Get.toNamed(RouteConfig.tuanOrder);
        } else if (id == 27) {
          //TODO：网格员中心
          // Get.toNamed(RouteConfig.tuanOrder);
        } else if (id == 5) {
          //我的拼团
          Get.toNamed(RouteConfig.collage);
        } else if (id == 13) {
          //TODO：社区团购
          // Get.toNamed(RouteConfig.tuanOrder);
        } else if (id == 14) {
          //TODO：分享赚
          // Get.toNamed(RouteConfig.tuanOrder);
        } else if (id == 15) {
          //TODO：分销员中心
          // Get.toNamed(RouteConfig.tuanOrder);
        } else if (id == 18) {
          //TODO：在线客服
          // Get.toNamed(RouteConfig.tuanOrder);
          if (state.keFuString.isNotEmpty) {
            var otherParams = {
              "productInfo": {},
              // "peerId": "10052439",
              "nickName": "${SpUtil.getString('empeName')}",
            };
            var clientId = '${SpUtil.getInt('empeNumId')}';
            var kefubaseUrl =
                'https://7moor.zrhsh.com/wapchat.html?fromUrl=&urlTitle=&language=ZHCN';
            kefubaseUrl = kefubaseUrl +
                '&accessId=' +
                state.keFuString +
                '&otherParams=' +
                jsonEncode(otherParams) +
                '&clientId=' +
                clientId;
            if (kIsWeb) {
              webpay(
                 kefubaseUrl  );
              return;
            }
            Get.toNamed(RouteConfig.webview, arguments: {
              "url":
                  kefubaseUrl,
            });
          }
        } else if (id == 8) {
          //积分商城
          Get.toNamed(RouteConfig.integralMall);
        } else if (id == 17) {
          //会员权益
          Get.toNamed(RouteConfig.membershipInterests);
        } else if (titleStr == 'KOC中心') {
          // Get.toNamed(RouteConfig.workbench);
        } else if (titleStr == '发票') {
          Get.toNamed(RouteConfig.issueInvoice);
        } else if (titleStr == '发票详情') {
          Get.toNamed(RouteConfig.invoiceDetails);
        } else if (titleStr == '我的流量') {
          Get.toNamed(RouteConfig.myTrafficUsers);
        } else if (titleStr == 'KOC中心4') {
          Get.toNamed(RouteConfig.signIn).then((value) {
            logic.signInRefresh(); // 签到成功 刷新
          });
        } else if (titleStr == '预售订单') {
          Get.toNamed(RouteConfig.preSaleOrder);
        } else if (titleStr == '帮助中心') {
          Get.toNamed(RouteConfig.helpPage);
        }
      },
      child: Container(
        width: setWidth(185),
        padding: EdgeInsets.only(
          top: setWidth(32),
          bottom: setWidth(12),
        ),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            Image.network(
              imageStr,
              width: setWidth(62),
              height: setWidth(62),
              fit: BoxFit.cover,
            ),
            SizedBox(
              height: setWidth(20),
            ),
            Text(
              titleStr,
              maxLines: 1,
              overflow: TextOverflow.ellipsis,
              style: TextStyle(
                color: Color(0xff333333),
                fontSize: setWidth(24),
              ),
            ),
          ],
        ),
      ),
    );
  }

  // 商品列表
  Widget _goodsListWidget() {
    List goodsList = state.goodList;
    return goodsList.isEmpty
        ? SizedBox()
        : Container(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Container(
                  height: setWidth(50),
                  padding: EdgeInsets.only(
                    top: setWidth(16),
                  ),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      Container(
                        width: setWidth(180),
                        height: setWidth(2),
                        color: Color(0xffd8d8d8),
                      ),
                      Container(
                        height: setWidth(6),
                        width: setWidth(6),
                        decoration: BoxDecoration(
                          color: Color(0xffd8d8d8),
                          borderRadius: BorderRadius.circular(setWidth(3)),
                        ),
                      ),
                      Container(
                        height: setWidth(6),
                        width: setWidth(6),
                        decoration: BoxDecoration(
                          color: Color(0xffd8d8d8),
                          borderRadius: BorderRadius.circular(setWidth(3)),
                        ),
                      ),
                      Container(
                        width: setWidth(180),
                        height: setWidth(2),
                        color: Color(0xffd8d8d8),
                      ),
                    ],
                  ),
                ),
                Padding(
                  padding: EdgeInsets.symmetric(horizontal: setWidth(30)),
                  child: Wrap(
                    spacing: setWidth(13),
                    runSpacing: setWidth(20),
                    children: goodsList
                        .asMap()
                        .map((key, value) {
                          return MapEntry(
                            key,
                            _goodsInformationWidget(index: key, goods: value),
                          );
                        })
                        .values
                        .toList(),
                  ),
                ),
              ],
            ),
          );
  }

  // 商品信息
  Widget _goodsInformationWidget({
    int index,
    Map goods,
  }) {
    bool soldOutBool = goods['style_store'] <= 0;
    return InkWell(
        onTap: () {
          String itemNumId = goods['default_item_num_id'].toString();
          String styleNumId = goods['style_num_id'].toString();
          String shopId = goods['shop_num_id'].toString();
          String cat1Id = goods['cat1_id'].toString();
          String ecStyleNumId = goods['ec_style_num_id'].toString();
          Get.toNamed(RouteConfig.goodsDetail, arguments: {
            'itemNumId': itemNumId,
            'styleNumId': styleNumId,
            'shopId': shopId,
            'cat1Id': cat1Id,
            'ecStyleNumId': ecStyleNumId,
            'typeIndex': goods['is_pre_sale'],
          });
        },
        child: Container(
          width: setWidth(338),
          height: setWidth(500),
          decoration: BoxDecoration(
            color: Colors.white,
            borderRadius: BorderRadius.circular(setWidth(10)),
          ),
          padding: EdgeInsets.only(
            left: setWidth(20),
            top: setWidth(20),
            right: setWidth(20),
          ),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Stack(
                alignment: Alignment.center,
                children: [
                  Container(
                    width: setWidth(298),
                    height: setWidth(298),
                    child: CachedNetworkImage(
                      imageUrl: goods['image_default_id'],
                      errorWidget: (context, url, error) {
                        return Container(
                          width: setWidth(298),
                          height: setWidth(298),
                          color: Color(0xffdddddd),
                        );
                      },
                      fit: BoxFit.cover,
                    ),
                  ),
                  soldOutBool
                      ? Container(
                          width: setWidth(120),
                          height: setWidth(120),
                          alignment: Alignment.center,
                          decoration: BoxDecoration(
                            color: Color(0xffbbbbbb).withOpacity(0.7),
                            borderRadius: BorderRadius.circular(setWidth(60)),
                          ),
                          child: Text(
                            '售罄',
                            style: TextStyle(
                              color: Colors.white,
                              fontSize: 15,
                            ),
                          ),
                        )
                      : SizedBox(),
                ],
              ),
              SizedBox(
                height: setWidth(10),
              ),
              Container(
                height: setWidth(80),
                child: Text(
                  goods['title'],
                  maxLines: 2,
                  style: TextStyle(
                    color: Color(0xff222222),
                    fontSize: 14,
                  ),
                ),
              ),
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  Row(
                    children: [
                      Text(
                        "${goods['price']}",
                        style: TextStyle(
                          color: Color(0xffea5504),
                          fontSize: 20,
                        ),
                      ),
                      Offstage(
                        offstage: index % 3 != 0,
                        child: Row(
                          children: [
                            SizedBox(
                              width: setWidth(14),
                            ),
                            Column(
                              children: [
                                SizedBox(
                                  height: setWidth(6),
                                ),
                                Text(
                                  "${goods['mkt_price']}",
                                  style: TextStyle(
                                    color: Color(0xff999999),
                                    fontSize: 12,
                                    decoration: TextDecoration.lineThrough,
                                  ),
                                ),
                              ],
                            ),
                          ],
                        ),
                      ),
                    ],
                  ),
                  if (goods['fresh_type'] != 8)
                    InkWell(
                      child: Image.asset(
                        'assets/images/shoppingCart_image.png',
                        width: setWidth(50),
                        height: setWidth(50),
                        color: !soldOutBool
                            ? Color(0xffEA5504)
                            : Color(0xffcccccc),
                        fit: BoxFit.cover,
                      ),
                      onTap: () {
                        if (!soldOutBool) {
                          if (goods['nospec'] == '1') {
                            logic.requestAddGoods(goods);
                          }
                        }
                      },
                    )
                ],
              ),
            ],
          ),
        ));
  }
}

class ClipperPath extends CustomClipper<Rect> {
  @override
  Rect getClip(Size size) {
    return new Rect.fromLTRB(0, 0, size.width, size.height - setWidth(40));
  }

  @override
  bool shouldReclip(CustomClipper<Rect> oldClipper) {
    return true;
  }
}

extension HexColor on Color {
  /// String is in the format "aabbcc" or "ffaabbcc" with an optional leading "#".
  static Color fromHex(String hexString) {
    final buffer = StringBuffer();
    if (hexString.length == 6 || hexString.length == 7) buffer.write('ff');
    buffer.write(hexString.replaceFirst('#', ''));
    return Color(int.parse(buffer.toString(), radix: 16));
  }

  /// Prefixes a hash sign if [leadingHashSign] is set to `true` (default is `true`).
  String toHex({bool leadingHashSign = true}) => '${leadingHashSign ? '#' : ''}'
      '${alpha.toRadixString(16).padLeft(2, '0')}'
      '${red.toRadixString(16).padLeft(2, '0')}'
      '${green.toRadixString(16).padLeft(2, '0')}'
      '${blue.toRadixString(16).padLeft(2, '0')}';
}
